package com.menglei.dailytasks.m0718;

import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.menglei.dailytasks.R;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private FrameLayout mContainer;
    /**
     * 当前数据
     */
    private TextView mContent;
    private String TAG = "MainActivity:";


    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main1);
        initView();
        initFragment();

        Map<String, Object> mMap = new HashMap<>();
        mMap.put("name", "高昶");


        MySharedPreferences msp = new MySharedPreferences(this, "preference.xml");
//        try {
//            //msp.putMap(mMap);
//            //msp.putBoolean("sex", true);
//            //msp.putString("hobby","drink");
//            //msp.putInt("age",10);
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

        Log.d("MySharedPreferences", String.valueOf(msp.getInt("age",-1)));
        Log.d("MySharedPreferences", msp.getString("name", ""));
        Log.d("MySharedPreferences", String.valueOf(msp.getBoolean("sex", false)));
    }


    private void initFragment() {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        PrefFragment prefFragment = new PrefFragment();
        ft.add(R.id.container, prefFragment, null);
        ft.commit();
    }

    private void initView() {
        mContainer = (FrameLayout) findViewById(R.id.container);
        mContent = (TextView) findViewById(R.id.content);
    }
}